package com.jinzecloud.reportapproval.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinzecloud.reportapproval.utils.PageUtils;
import com.jinzecloud.reportapproval.utils.Query;

import com.jinzecloud.reportapproval.mapper.EntrepreneurMapper;
import com.jinzecloud.reportapproval.bean.Entrepreneur;
import com.jinzecloud.reportapproval.service.EntrepreneurService;


@Service("entrepreneurService")
public class EntrepreneurServiceImpl extends ServiceImpl<EntrepreneurMapper, Entrepreneur> implements EntrepreneurService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<Entrepreneur> entrepreneurQueryWrapper = new QueryWrapper<>();
        entrepreneurQueryWrapper.like("name", params.get("key"))
                .or().like("address", params.get("key"))
                .or().like("phone", params.get("key"))
                .or().like("email", params.get("key"))
                .or().like("linkman", params.get("key"))
                .or().like("linkphone", params.get("key"))
                .or().like("zipcode", params.get("key"))
                .or().like("actual_production_address", params.get("key"));
        IPage<Entrepreneur> page = this.page(
                new Query<Entrepreneur>().getPage(params),
                entrepreneurQueryWrapper
        );

        return new PageUtils(page);
    }

    @Override
    public void upStatus(Entrepreneur entrepreneur) {
        UpdateWrapper<Entrepreneur> entrepreneurUpdateWrapper = new UpdateWrapper<>();
        entrepreneurUpdateWrapper.set("status",entrepreneur.getStatus()).eq("id",entrepreneur.getId());
        this.update(entrepreneurUpdateWrapper);
    }

    @Override
    public List<Entrepreneur> geteoptions() {
        QueryWrapper<Entrepreneur> queryWrapper = new QueryWrapper<Entrepreneur>().select("id", "name");
        return this.list(queryWrapper);
    }

    @Override
    public Entrepreneur getByName(String companyName) {
        QueryWrapper<Entrepreneur> queryWrapper = new QueryWrapper<Entrepreneur>().eq("name",companyName);
        Entrepreneur entrepreneur = this.getOne(queryWrapper);
        if(entrepreneur!=null){
            return entrepreneur;
        }
        return null;
    }

}